/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simplemetrosystem.model.Command.EditCommand;

import java.util.ArrayList;
import javax.swing.JOptionPane;
import simplemetrosystem.control.ElementManager;
import simplemetrosystem.model.Command.Command;
import simplemetrosystem.model.Element.MetroEdge;
import simplemetrosystem.model.Element.MetroLine;
import simplemetrosystem.model.Element.MetroStation;
import simplemetrosystem.model.charlanguage.NameMap;

/**
 *
 * @author Eric Qian
 */
public class RemoveLineCommand implements Command {

    /**
     * 
     * @param line 
     */
    public RemoveLineCommand(MetroLine line) {
        this.line = line;
        edges = ElementManager.getInstance().getEdgesOfLine(line);
    }

    public void execute() {
        if (line.getStatus().equals(MetroLine.STATUS_METRO)) {
            ElementManager.getInstance().removeLine(line);
        } else {
            JOptionPane.showMessageDialog(null, NameMap.getInstance().getName("This Line can't be removed"),
                    NameMap.getInstance().getName("WARNING"), JOptionPane.WARNING_MESSAGE);
        }
    }

    public void undo() {
        if (line.getStatus().equals(MetroLine.STATUS_METRO)) {
            ElementManager.getInstance().addLine(line);
            for (int i = 0; i < edges.size(); i++) {
                ElementManager.getInstance().addEdge(edges.get(i));
            }
        }
    }
    private MetroLine line;
    private ArrayList<MetroEdge> edges;
}
